<template>
  <div class="container">
    <h1 id="narratorText">We are together, already</h1>
  </div>
</template>

<script>
import {defineComponent, onMounted } from "vue";

export default ({
  setup() {
    onMounted(() => {
      spanText(document.getElementById("narratorText"));
    });
  },
});

function spanText(text) {
  var string = text.innerText;
  var spaned = "";
  for (var i = 0; i < string.length; i++) {
    if (string.substring(i, i + 1) === " ")
      spaned += string.substring(i, i + 1);
    else spaned += "<span>" + string.substring(i, i + 1) + "</span>";
  }
  text.innerHTML = spaned;
}
</script>

<style>
@import url("https://fonts.googleapis.com/css?family=Oswald:300,400,500,600,700&display=swap");
body {
  margin: 0;
  padding: 0;
}

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Oswald', helvetica;
  color: black;
  font-size: 30px;
}
.container h1 {
  position: relative;
}
.container h1::before, .container h1::after {
  content: "";
  position: absolute;
  background: black;
  width: 2px;
  margin: auto 0;
  top: 5px;
  bottom: 0;
}
.container h1::before {
  left: 50%;
  animation: leftSlide 1.3s cubic-bezier(0.68, -0.55, 0.265, 1.5) forwards;
}
.container h1::after {
  animation: rightSlide 1.3s cubic-bezier(0.68, -0.55, 0.265, 1.5) forwards;
}
.container h1 span {
  letter-spacing: 3px;
  font-weight: 300;
  display: inline-block;
  opacity: 0;
  text-transform: uppercase;
  animation-iteration-count: 1;
  animation: fadeIn forwards 0.8s ease-out;
}
.container h1 span:nth-child(1) {
  animation-delay: 0.8s;
}
.container h1 span:nth-child(2) {
  animation-delay: 0.7s;
}
.container h1 span:nth-child(3) {
  animation-delay: 0.6s;
}
.container h1 span:nth-child(4) {
  animation-delay: 0.5s;
}
.container h1 span:nth-child(5) {
  animation-delay: 0.4s;
}
.container h1 span:nth-child(6) {
  animation-delay: 0.4s;
}
.container h1 span:nth-child(7) {
  animation-delay: 0.5s;
}
.container h1 span:nth-child(8) {
  animation-delay: 0.6s;
}
.container h1 span:nth-child(9) {
  animation-delay: 0.7s;
}
.container h1 span:nth-child(10) {
  animation-delay: 0.8s;
}

@keyframes fadeIn {
  0% {
    transform: scale(0.2);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes leftSlide {
  0% {
    opacity: 0;
    left: 50%;
    height: 5%;
  }
  100% {
    opacity: 1;
    left: -6%;
    height: 75%;
  }
}
@keyframes rightSlide {
  0% {
    opacity: 0;
    right: 50%;
    height: 5%;
  }
  100% {
    opacity: 1;
    right: -6%;
    height: 75%;
  }
}

</style>